package com.linsen.core.log.config;

import com.linsen.core.common.annotation.AutoConfiguration;
import com.linsen.core.common.config.ModuleConfig;
import com.linsen.core.common.factory.YamlPropertySourceFactory;
import com.linsen.core.log.aspect.LogAspect;
import com.linsen.core.log.listener.LogListener;
import com.linsen.core.log.props.LinsenLogProperties;
import com.linsen.core.rabbitmq.service.RabbitMQService;
import com.linsen.core.redis.util.RedisSecurityUtil;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author zhaoyong
 * @date 2023/3/12
 */
@EnableAsync
@AutoConfiguration
@EnableConfigurationProperties({LinsenLogProperties.class})
@PropertySource(factory = YamlPropertySourceFactory.class, value = "classpath:linsen-log.yml")
public class LinsenLogAutoConfiguration {
    @Bean
    public LogAspect logAspect(ApplicationContext applicationContext, RedisSecurityUtil redisSecurityUtil, ModuleConfig moduleConfig) {
        return new LogAspect(applicationContext, redisSecurityUtil, moduleConfig);
    }

    @Bean
    public LogListener logListener(LinsenLogProperties logProperties, RabbitMQService rabbitMQService) {
        return new LogListener(logProperties, rabbitMQService);
    }
}
